/*_____________________________________________________________________________
||
|| swip.h
||
|| Jinfeng Zhuang, 2024.W17
||______________________________________________________________________________
*/

#ifndef SWIP_H
#define SWIP_H

typedef unsigned int U32;

/*_____________________________________________________________________________
||
|| swip_event_handler
||
|| like API: ip_command(param1, param2)
||           uart1_send(buffer, size)
||           uart2_send(buffer, size)
||
|| The parameter 'ip' is used to distinguish UART1, UART2,... with same handler
||______________________________________________________________________________
*/

typedef U32 (*swip_event_handler)(U32 ip, U32 command, U32 param1, U32 param2);

enum swip_ip
{
    /* SOC */
    SWIP_SOC_CORE,
    SWIP_SOC_CLOCK,
    SWIP_SOC_POWER,
    SWIP_SOC_IOMUX,
    SWIP_SOC_INTCTRL,
    SWIP_SOC_SYSTICK,
    SWIP_SOC_GPIO,
    SWIP_SOC_WDT,
    SWIP_SOC_UART1,
    SWIP_SOC_UART2,
    SWIP_SOC_TIMER1,
    SWIP_SOC_TIMER2,
    SWIP_SOC_CAN1,
    SWIP_SOC_CAN2,
    SWIP_SOC_SDIO,

    /* Software timer: drive period tasks */
    SWIP_SOFTWARE_TIMER,

    SWIP_TEST,

    /* Devices: Handle Hardware related features, such as delay... */
    SWIP_DEV_LTC68xx,
    SWIP_DEV_PCS,
    SWIP_DEV_EEPROM,
    SWIP_DEV_RTC,
    SWIP_DEV_ADX111,
    SWIP_DEV_TEMP,
    SWIP_DEV_BALANCE,
    SWIP_DEV_SNMP,
    SWIP_DEV_LCD,
    SWIP_DEV_PC,

    /* Policy: Periodly */
    SWIP_TASK_BATT,
    SWIP_TASK_RELAY,
    SWIP_TASK_SOC,
    SWIP_TASK_SOH,
    SWIP_TASK_OVP,
    SWIP_TASK_FAN,
    SWIP_TASK_SYNC_SLAVE,
    SWIP_TASK_SYNC_MASTER,
    SWIP_TASK_LIMIT_CURR,

    SWIP_MAX,
};

// The common commands
enum swip_command
{
    SWIP_CMD_LOAD,          // load the default values
    SWIP_CMD_CLOCK_DRIVE,   // clock
    SWIP_CMD_CLOCK_GET,
    SWIP_CMD_CLOCK_SET,
    SWIP_CMD_ENABLE,       // 0: disable, 1: enable
    SWIP_CMD_MODE_SET,     // BLOCK, INT, DMA
    SWIP_CMD_INT_ENABLE,   // 0: disable, 1: enable
    SWIP_CMD_CPU_WRITE,
    SWIP_CMD_CPU_READ,
    SWIP_CMD_IP_WRITE,
    SWIP_CMD_IP_READ,
    SWIP_CMD_USER,
};

struct swip
{
    U32                id;   // enum swip_ip
    swip_event_handler handler;
};

U32 swip_call(U32 ip, U32 cmd, U32 param1, U32 param2);

#endif
